﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TVProgramAnalyst.Tools;
using TVProgramAnalyst.TimeLine;
using TVProgramAnalyst.ReportForm;
using TVProgramAnalyst.Options;
using System.Configuration;

namespace TVProgramAnalyst
{
    public partial class Main : Form
    {
        private int childFormNumber = 0;

        public Main()
        {
            InitializeComponent();
        }

        private void ShowNewForm(object sender, EventArgs e)
        {
            Form childForm = new Form();
            childForm.MdiParent = this;
            childForm.Text = "Window " + childFormNumber++;
            childForm.Show();
        }

        private void OpenFile(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            openFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = openFileDialog.FileName;
            }
        }

        private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            saveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = saveFileDialog.FileName;
            }
        }

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void CutToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void ToolBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            toolStrip.Visible = toolBarToolStripMenuItem.Checked;
        }

        private void StatusBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            statusStrip.Visible = statusBarToolStripMenuItem.Checked;
        }

        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();
            }
        }

        private void combineTimelineToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TimeLine.frmCombineWizard frmCombine = new TimeLine.frmCombineWizard();
            frmCombine.MdiParent = this;
            frmCombine.WindowState = FormWindowState.Maximized;
            frmCombine.Show();
        }

        private void Main_Load(object sender, EventArgs e)
        {
            //frmTimelineExplorer frm = new frmTimelineExplorer();
            //frm.MdiParent = this;
            //frm.Show();
        }

        private void Main_FormClosing(object sender, FormClosingEventArgs e)
        {
            global.Default.Save();
            TPA.DataAccess.BLLFactory.SystemCodeBLL.Dispose();
            TPA.DataAccess.BLLFactory.ProgramBLL.Dispose();
        }

        private void systemCodeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmSystemCode newfrm = new frmSystemCode();
            newfrm.ShowDialog(this);
            newfrm.Dispose();
        }

        private void programPropertiesEditorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmSystemCode newfrm = new frmSystemCode();
            newfrm.ShowDialog(this);
            newfrm.Dispose();
        }

        private void programEditorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmProgramResult frm = new frmProgramResult();
            frm.MdiParent = this;
            frm.Show();
        }


        private void AutoWizardToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmAutoWizard frm = new frmAutoWizard();
            frm.ShowDialog(this);
            frm.Dispose();
        }

        private void searchTimelineToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmTimelineExplorer frm = new frmTimelineExplorer();
            frm.MdiParent = this;
            frm.Show();
        }

        private void reportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //frmReportViewer frm = new frmReportViewer();
            //frm.ShowDialog(this);
            //frm.Dispose();

        }

        private void btnChannelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmChannel frm = new frmChannel();
            frm.MdiParent = this;
            frm.Show();
        }

        private void advHourlyTimeKPIToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmReport frm = new frmReport();
            frm.MdiParent = this;
            frm.Text = "小时广告比例报表";
            frm.WindowState = FormWindowState.Maximized;
            frm.Show();
            frm.RefreshReport("http://localhost/reportserver", "/TPA_SSRSP/HourlyAdvKPI");
        }

        private void advPercentAppToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmReport frm = new frmReport();
            frm.MdiParent = this;
            frm.Text = "广告比例与满意度报表";
            frm.WindowState = FormWindowState.Maximized;
            frm.Show();
            frm.RefreshReport("http://localhost/reportserver", "/TPA_SSRSP/AdvPercentandApp");
        }

        private void optionsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmOptions frm = new frmOptions();
            frm.ConfigTarget = global.Default;
            frm.StartPosition = FormStartPosition.CenterParent; 
            frm.ShowDialog(this);
            //global.Default. = frm.ConfigTarget;
            frm.Dispose();
        }

        private void connectionStringToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmOptions frm = new frmOptions();
            frm.ConfigTarget = ConfigurationManager.ConnectionStrings[1];
            frm.ShowDialog(this);
            frm.StartPosition = FormStartPosition.CenterParent;
            //ConfigurationManager.ConnectionStrings[1] = frm.ConfigTarget as ConnectionStringSettings;
            frm.Dispose();
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AboutBox ab = new AboutBox();
            ab.ShowDialog(this);
            ab.StartPosition = FormStartPosition.CenterParent;
            ab.Dispose();
        }

        private void processDataToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmProcessSSASResult frm = new frmProcessSSASResult();
            frm.ShowDialog(this);
            frm.Dispose();
        }

        private void 广告时长报表ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmReport frm = new frmReport();
            frm.MdiParent = this;
            frm.Text = "广告比例与满意度报表";
            frm.WindowState = FormWindowState.Maximized;
            frm.Show();
            frm.RefreshReport("http://localhost/reportserver", "/TPA_SSRSP/BroadcastLength");
        }

    }
}
